﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Common;
using System.Reflection;
using Fast.Framework.Models;


namespace Fast.Framework.Interfaces
{

    /// <summary>
    /// Ado接口类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IAdo<TDbOptions> : IDisposable where TDbOptions : DbOptions
    {

        /// <summary>
        /// 数据库提供商工厂
        /// </summary>
        DbProviderFactory DbProviderFactory { get; }

        /// <summary>
        /// 参数符号
        /// </summary>
        string ParameterNotation { get; }

        /// <summary>
        /// 标识符
        /// </summary>
        string Identifier { get; }

        /// <summary>
        /// 数据库选项
        /// </summary>
        TDbOptions DbOptions { get; }

        /// <summary>
        /// 执行非查询异步
        /// </summary>
        /// <param name="sqlOrProName">Sql语句或存储过程</param>
        /// <param name="dbParameters">数据库参数</param>
        /// <param name="isProcedure">是否存储过程</param>
        /// <param name="isTransaction">是否事务</param>
        /// <returns></returns>
        Task<int> ExecuteNonQueryAsync(string sqlOrProName, List<DbParameter> dbParameters = null, bool isProcedure = false, bool isTransaction = false);

        /// <summary>
        /// 执行标量异步
        /// </summary>
        /// <typeparam name="T">需要转换的类型</typeparam>
        /// <param name="sqlOrProName">Sql语句或存储过程</param>
        /// <param name="dbParameters">数据库参数</param>
        /// <param name="isProcedure">是否存储过程</param>
        Task<T> ExecuteScalarAsync<T>(string sqlOrProName, List<DbParameter> dbParameters = null, bool isProcedure = false);

        /// <summary>
        /// 执行读取器异步
        /// </summary>
        /// <param name="sqlOrProName">sql语句或者存储过程</param>
        /// <param name="dbParameters">数据库参数</param>
        /// <param name="isProcedure">是否存储过程</param>
        /// <returns></returns>
        Task<DbDataReader> ExecuteReaderAsync(string sqlOrProName, List<DbParameter> dbParameters = null, bool isProcedure = false);

        /// <summary>
        /// Sql参数构建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">实体</param>
        List<DbParameter> SqlParametersBuild<T>(T entity) where T : class;

        /// <summary>
        /// Sql参数构建
        /// </summary>
        /// <param name="keyValues"></param>
        /// <returns></returns>
        List<DbParameter> SqlParametersBuild(Dictionary<string, object> keyValues);
    }
}
